<?php
namespace Portal\Controller;
use Common\Controller\HomebaseController;

class SiteController extends HomebaseController {
    //添加新场馆
	public function addsite() {
		$this->display(":addsite");
		if($_POST['sitename']&&$_POST['addr']&&$_POST['addrtel']){
			$Site=M('site');
			$arr=$_POST;
			$msg=$Site->add($arr);
			if($msg){
				$this->succ('showsite');
			}
			else{
				$this->err('showsite');
			}
		}
		else{
			echo '请添加信息！';
		}
	}
	//场馆展示（修改、删除）
	public function showsite() {
		$Site=M('site');
        $msg=$Site->select();
		$this->assign('msg',$msg);
    	$this->display(":showsite");
    }
	//删除场馆
	public function delsite() {
		$s=$_GET['s'];
		$Site=M('site');
		$msg=$Site->where("sitename='$s'")->delete();//where语句中的变量需要引号
		if($msg){
			$this->succ('showsite');
		}
	}
	//编辑场馆
	public function editsite() {
			$Site=M('site');
			$s=$_GET['s'];
			$msg=$Site->where("sitename='$s'")->select();
			$this->assign('msg',$msg);
			$this->display(":editsite");
			$arr=$_POST;
			
			if($arr['sitename']&&$arr['addr']&&$arr['addrtel']){
			//$arr['sitename']=$_POST['sitename'];
			//$arr['addr']=$_POST['addr'];
			//$arr['addrtel']=$_POST['addrtel'];
				$msg=$Site->where("sitename='$s'")->save($arr);
				if($msg){
					$this->succ('showsite');
				}
				else{
					$this->err('showsite');
				}
			}
	}
	//操作成功
	public function succ($m){
		$C='Site';
		$this->assign('m',$m)->assign('C',$C);
		$this->display(':success');
	}
	//操作失败
	public function err($m){
		$C='Site';
		$this->assign('m',$m)->assign('C',$C);
		$this->display(':err');
	}
}
